
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class GameDemo1 extends StatefulWidget {
  const GameDemo1({super.key});

  @override
  State<GameDemo1> createState() => _GameDemo1State();
}

class _GameDemo1State extends State<GameDemo1> {
  @override
  Widget build(BuildContext context) {
    return GameWidget(
      game: FlameGame(world: MyWorld()),
      backgroundBuilder: (BuildContext context){
        return Container(
          color: Colors.white,
        );
      },
    );
  }
}

class MyWorld extends World {
  @override
  Future<void> onLoad() async {
    add(Player(position: Vector2(0, 0)));
  }
}

class Player extends SpriteComponent with TapCallbacks{
  Player({super.position}) :
        super(size: Vector2.all(200), anchor: Anchor.center);

  @override
  Future<void> onLoad() async {
    sprite = await Sprite.load('player_man.png');
  }

  @override
  void onTapUp(TapUpEvent info) {
    size += Vector2.all(50);
  }
}
